package main;

import java.util.Collection;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;

public class PlayerInfo {
	private final Player player;
	private final double health;
	private final float exp;
	private final int food;
	private final float saturation;
	private final ItemStack[] inventory;
	private final ItemStack[] armor;
	private final Collection<PotionEffect> potionEffects;
	private final Location location;
	
	public PlayerInfo(Player player) {
		this.player = player;
		
		health = player.getHealth();		
		exp = player.getExp();		
		food = player.getFoodLevel();		
		saturation = player.getSaturation();	
		inventory = player.getInventory().getContents();
		armor = player.getInventory().getArmorContents();		
		potionEffects = player.getActivePotionEffects();		
		location = player.getLocation();
	}
	
	public void restore() {
		player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
		player.setHealth(health);
		player.setExp(exp);
		player.setFoodLevel(food);
		player.setSaturation(saturation);
		player.getInventory().setContents(inventory);
		player.getInventory().setArmorContents(armor);
		for (PotionEffect effect : player.getActivePotionEffects()) {
			player.removePotionEffect(effect.getType());
		}
		player.addPotionEffects(potionEffects);
		player.teleport(location);
	}
}
